package lib.quasar.widget.image;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import lib.quasar.util.LogUtil;

public final class BitmapImageView extends android.support.v7.widget.AppCompatImageView {

    public BitmapImageView(Context context) {
        super(context);
    }

    public BitmapImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public BitmapImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {

        try {
            super.onDraw(canvas);
        } catch (Exception e) {
            LogUtil.e("BitmapImageView", e.getMessage(), e);
        }
    }

    @Override
    public void setImageBitmap(Bitmap bm) {
        super.setImageBitmap(bm);

        if (null != mOnImageChangeListener) {
            mOnImageChangeListener.onFinish();
        }
    }

    private OnImageChangeListener mOnImageChangeListener;

    public interface OnImageChangeListener {

        void onFinish();
    }

    public void setOnImageChangeListener(OnImageChangeListener mOnImageChangeListener) {
        this.mOnImageChangeListener = mOnImageChangeListener;
    }
}
